home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / hf / dsp / dspdsk3 / mdm_com2.asm < prev    next >
Encoding:
Assembly Source File  |  1993-11-12  |  10.8 KB  |  261 lines

  1. ;************************************************
  2. ; TMS320C26 DSK RS232 INTERFACE DRIVER - PROTOTYPE!
  3. ; Keith Larson
  4. ; DSP Applications
  5. ; Texas Instruments Inc
  6. ; (C)opyright 1992, 1993
  7. ; Modified: 11/12/93 - Johan B. Forrer
  8. ;     Change conf 1 -> conf 2 so that all operations
  9. ;     leaves 1024 words of code and 512 words of data
  10. ;************************************************/
  11. YES     .set    1
  12. NO      .set    0
  13. ;-----------------------------------------------------------;
  14. TEMP            .set   0x60     ;
  15. WORD16          .set   0x61     ;
  16. PADDR           .set   0x62     ;
  17. WORD            .set   0x63     ;
  18. TEMPx           .set   0x64     ;
  19. _IMR            .set   0x65     ;
  20. BITLEN          .set   0x66     ;RS232 bitwidth in C26 clock ticks
  21. BITLEN2         .set   0x67     ;RS232 bitwidth in C26 clock ticks
  22. USR_PRD         .set   0x68
  23. USR_AR0         .set   0x69
  24. USR_AR1         .set   0x6A
  25. USR_AR2         .set   0x6B
  26. USR_AR3         .set   0x6C
  27. STAT0           .set   0x6D
  28. STAT1           .set   0x6E
  29. ;----------------------------------------------------------------
  30.         .include  "mmregs.asm"
  31.         .ps     0xFA00          ;
  32.         B       KLKRNL          ;FA00  RS
  33.         B       KLKRNL          ;FA02  INT0
  34.         B       KLKRNL          ;FA04  INT1
  35.         B       KLKRNL          ;FA06  INT2
  36.        ;B       QFIX            ;FA08  TINT -> RECOVER ARP
  37.         ret
  38.         ret
  39.         ret                     ;FA0A  RINT
  40.         ret                     ;
  41.         ret                     ;FA0C  XINT
  42.         ret                     ;
  43.         B       KLKRNL          ;FA0E  TRAP
  44.         ;--------------------------------------------------------------
  45.         b       CMD             ;FA10  JUMP table to KLKRNL routines
  46.         b       XMIT            ;FA12
  47.         b       XMIT16          ;FA14
  48.         b       RECV            ;FA16
  49.         b       RECV16          ;FA18
  50.         b       CXMIT           ;FA1A
  51.         ;--------------------------------------------------------------
  52. QFIX    sst     STAT0           ; save STATUS & DP
  53.         sst1    STAT1           ; save ARP
  54.         ldpk    0               ;
  55.         lst1    STAT1           ; restore ARP
  56.         ldp     STAT0           ; restore DP
  57.         ret                     ;
  58.         ;--------------------------------------------------------------
  59. KLKRNL: dint                    ;
  60.         sxf                     ;initialize line
  61.         ldpk    0               ;
  62.         conf    2               ;
  63.         zac                     ;
  64.         sacl    IMR             ;
  65.         lac     BITLEN,1        ; 2 x
  66.         add     BITLEN          ; 3 x
  67.         addk    4
  68.         sfr                     ; 1.5 x
  69.         sfr                     ; 1/2
  70.         sacl    BITLEN          ;Store Baud Timer
  71.         sacl    PRD             ;
  72.         sfr                     ;
  73.         sacl    BITLEN2         ;Store Baud Timer/2
  74.         ;-----------------------
  75. CMD     call    RECV,*,AR0      ;get 8 bit CMD from host
  76.         bz      CMD             ;
  77.         subk    1               ;
  78.         bz      W_PS            ;1 = write program space
  79.         subk    1               ;
  80.         bz      R_PS            ;2 = read program space
  81.         subk    1               ;
  82.         bz      W_DS            ;3 = write data space
  83.         subk    1               ;
  84.         bz      R_DS            ;4 = read data space
  85.         subk    1               ;
  86.         bnz     USRCMD          ;5 = Execute program at next word
  87.         call    RECV16          ;
  88. ;       lac     WORD16          ;
  89.         bacc                    ;
  90. USRCMD  subk    1               ;
  91.         bz      BR_PS           ;6 = block read program space
  92.         subk    1               ;
  93.         bz      BR_DS           ;7 = block read data space
  94.         subk    1               ;
  95.         bnz     CMD             ;8 = return to TOS, usually user code
  96.         ret
  97. ;============================================================
  98. ; W_PS & R_PS are used to access program memory
  99. ;============================================================
  100. W_PS    call    KRNL            ;
  101. W_PS2   call    RECV16          ;copy length words to PS
  102.         sacl    WORD            ;
  103.         lac     PADDR           ;ACCU=src address
  104.         tblw    WORD            ;
  105.         addk    1               ;
  106.         sacl    PADDR           ;
  107.         larp    AR3             ;
  108.         banz    W_PS2,*-,AR2    ;
  109.         b       CMD             ;
  110.         ;------------------------
  111. BR_PS   ; NOT IMPLIMENTED!!!
  112.         ;------------------------
  113. R_PS    call    KRNL            ;
  114. R_PS2   lac     PADDR           ;
  115.         tblr    TEMP            ;
  116.         addk    1               ;
  117.         sacl    PADDR           ;
  118.         lac     TEMP            ;
  119.         call    XMIT16          ;
  120.         larp    AR3             ;
  121.         banz    R_PS2,*-,AR2    ;next word
  122.         b       CMD             ;
  123. ;============================================================
  124. ; W_DS & R_DS are used to access data memory
  125. ;============================================================
  126. W_DS    call    KRNL            ;
  127. W_DS2   call    RECV16          ;build data word
  128.         larp    AR2             ;
  129.         sacl    *+,0,AR3        ;write the word   <<< missing shift!!!
  130.         banz    W_DS2,*-,AR2    ;
  131.         b       CMD             ;
  132.         ;------------------------
  133. R_DS    call    KRNL            ;
  134. R_DS2   larp    AR2             ;get word
  135.         lac     *+,0            ;
  136.         call    XMIT16,*        ;
  137.         larp    AR3             ;
  138.         banz    R_DS2,*-        ;next word
  139.         b       CMD             ;
  140.         ;------------------------
  141. BR_DS   call    KRNL            ;
  142. BR_DS2  larp    AR2             ;get word
  143.         lac     *+,0            ;
  144.         call    CXMIT,*         ;transmit chars W/O handshake
  145.         call    CXMIT,*         ;
  146.         larp    AR3             ;
  147.         banz    BR_DS2,*-       ;next word
  148.         b       CMD             ;
  149. ;============================================================
  150. ; KRNL is common to all block transfers
  151. ;============================================================
  152. KRNL    call    RECV16          ;1 st word is address
  153.         lar     AR2,WORD16      ;
  154.         sar     AR2,PADDR       ;
  155.         call    RECV16          ;2 nd word is length-1
  156.         lar     AR3,WORD16      ;
  157.         larp    AR2             ;
  158.         ret                     ;
  159. ;============================================================
  160. ; RECV returns word in bottom 8 bits of ACCL
  161. ;============================================================
  162. RECV16:
  163.         call    RECV            ;recv LO
  164.         sacl    WORD16          ;
  165.         call    RECV            ;recv HI
  166.         rptk    7               ;
  167.         sfl                     ;build HI+LO
  168.         or      WORD16          ;
  169.         sacl    WORD16          ;
  170.         ret                     ;
  171.         ;------------------------
  172. RECV    call    SAVE
  173.         call    TINT_ON
  174.         lark    AR1,8           ; take 9 samples (START >> shifted out!)
  175.         lac     BITLEN2         ; Load bitlen/2
  176.         sacl    PRD             ;
  177. WSBIT   bioz    SBIT,*,AR0      ; wait for start bit
  178.         b       WSBIT           ;
  179. SBIT    sach    TIM             ; Set   TINT (ACCU_hi = 0)
  180.         idle                    ; Clear TINT and load BITLEN/2 into TIM
  181.         lac     BITLEN          ; Load bitlen first idle will be bitlen/2
  182.         sacl    PRD             ;
  183.         zac                     ; Bits are add/shifted -> accu (must start 0)
  184.         ;------------------------
  185. NBIT    idle                    ; wait bitlen  (1st time is bitlen/2)
  186. SKIP    sfr                     ; shift to new posn
  187.         bioz    RB0,*,AR1       ; test bit
  188. RB1     addk    0x80            ; if 1, add new bit
  189. RB0     banz    NBIT,*-,AR0     ; last bit?
  190.         andk    0xff            ;
  191.         bioz    $               ; wait for STOP before RET
  192.       ;  idle
  193.         call    RESTORE         ;
  194.         b       TINT_OFF        ; branch -> ret (save a word!)
  195. ;       call    TINT_OFF        ;
  196. ;       ret                     ; ACCU = RECEIVED CHAR
  197. ;============================================================
  198. ; XMIT assumes word is in bottom 8 bits of ACCL
  199. ;============================================================
  200. XMIT16: call    XMIT            ;xmit LO
  201. ;       call    XMIT            ;xmit HI  Fall thru saves 3 words!
  202. ;       ret                     ;
  203. ;------------------------------------------------------------
  204. XMIT    call    SAVE            ;
  205.         ldpk    TEMPx           ;
  206.         sacl    TEMPx           ;
  207.         call    RECV            ; Handshake with slow host
  208.         lac     TEMPx           ;
  209. CXMIT   call    SAVE            ;
  210.         call    TINT_ON         ;
  211.         sfl                     ; first bit is 0 (Start bit)
  212.         lark    AR1,8           ; 1 start, 8 DATA
  213.         idle                    ; synch 1 st bit
  214.         idle                    ;
  215. SENDBIT ror                     ; TEMP = ........X XXXXXXXX0
  216.         bnc     XB0             ;
  217.         sxf                     ;
  218.         b       XB1             ;
  219. XB0     rxf                     ;
  220. XB1     idle                    ; wait for bit
  221.         mar     *,AR1           ; TINT sets ARP=0
  222.         banz    SENDBIT,*-,AR0  ; send another bit?
  223.         sxf                     ;
  224.         idle                    ; Stop bit
  225.         idle                    ; Stop bit
  226.         call    RESTORE         ;
  227. ;       call    TINT_OFF        ;
  228. ;       ret                     ;
  229. ;--------------------------------
  230. TINT_OFF ldpk    IMR            ;
  231.          lar     AR0,_IMR       ;Restore old IMR
  232.          sar     AR0,IMR        ;
  233.          ret                    ;
  234. ;--------------------------------
  235. TINT_ON ldpk    IMR             ;
  236.         lar     AR0,BITLEN      ; Load bitlen
  237.         sar     AR0,PRD         ;
  238.         lar     AR0,IMR         ;Keep old IMR
  239.         sar     AR0,_IMR        ;
  240.         lark    AR0,0x8         ;Enable only TINT
  241.         sar     AR0,IMR         ;
  242.         ret                     ;
  243. ;--------------------------------
  244. SAVE:   ldpk    USR_AR0         ; NOTE: Accumulator is used to pass
  245.         sar     AR0,USR_AR0     ;       values and is not saved!
  246.         sar     AR1,USR_AR1     ;
  247.         sar     AR2,USR_AR2     ;
  248.         sar     AR3,USR_AR3     ;
  249.         lar     AR0,PRD         ;
  250.         sar     AR0,USR_PRD     ;
  251.         ret                     ;
  252. ;--------------------------------
  253. RESTORE ldpk    USR_AR0         ; NOTE: Accumulator is used to pass
  254.         lar     AR0,USR_PRD     ;       values and is not saved!
  255.         sar     AR0,PRD         ;
  256.         lar     AR0,USR_AR0     ;
  257.         lar     AR1,USR_AR1     ;
  258.         lar     AR2,USR_AR2     ;
  259.         lar     AR3,USR_AR3     ;
  260.         ret                     ;
  261.